package params

import "net/url"

type ParamVarCollection struct {
	Params map[string][]string
}

// Get 获取参数
func (p *ParamVarCollection) Get(name string) *Variable {
	if value, ok := p.Params[name]; ok {
		return &Variable{
			Name:  name,
			Value: value,
		}
	}
	return nil
}

// All 获取所有参数
func (p *ParamVarCollection) All() []*Variable {
	vars := make([]*Variable, 0)
	for name, value := range p.Params {
		vars = append(vars, &Variable{Name: name, Value: value})
	}
	return vars
}

// Has 判断参数是否存在
func (p *ParamVarCollection) Has(name string) bool {
	return url.Values(p.Params).Has(name)
}

// Add 添加参数
func (p *ParamVarCollection) Add(name string, value string) *ParamVarCollection {
	url.Values(p.Params).Add(name, value)
	return p
}

// Del 删除参数
func (p *ParamVarCollection) Del(name string) *ParamVarCollection {
	url.Values(p.Params).Del(name)
	return p
}

// Set 设置参数
func (p *ParamVarCollection) Set(name string, value string) *ParamVarCollection {
	url.Values(p.Params).Set(name, value)
	return p
}
